//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2006
//
// Set routing graph node status.
//

# include "StdAfx.h"
# include "Resource.h"
# include "SetRGNodeExternal.h"
# include "UndoRedo.h"

class CSetRGNodeExternalAction : public CEditAction {
  public:
	CSetRGNodeExternalAction (rgnode_t & _node, bool _bIsExternal) :
		m_node (_node),
		m_bIsExternal (_bIsExternal)
	{}

	virtual void GetName (string_t & _str) const;
	virtual cu_t CanUndo () const {return cuYes;}
	virtual bool Do ();
	virtual void Undo ();
	virtual void Redo ();

  private:
	rgnode_t & m_node;
	const bool m_bIsExternal;
};

void CSetRGNodeExternalAction::GetName (string_t & _str) const {
	_str.append ("change node");
}

bool CSetRGNodeExternalAction::Do () {
	CCritSec::CLock lock (g_cs);

	m_node.bIsExternal = m_bIsExternal;

	return true;
}

void CSetRGNodeExternalAction::Undo () {
	CCritSec::CLock lock (g_cs);

	m_node.bIsExternal = ! m_bIsExternal;
}

void CSetRGNodeExternalAction::Redo () {
	CSetRGNodeExternalAction::Do ();
}

/////////////////////////////////////////////////

void SetRGNodeExternal (rgnode_t & _node, bool _bIsExternal) {
	PerformEditAction (new CSetRGNodeExternalAction (_node, _bIsExternal));
}